package gy.rpc.client;

import gy.rpc.api.dto.servicedto.UserDTO;
import gy.rpc.client.structureIntfc.IClientInvocationHandle;

import java.lang.reflect.Method;

/**
 * @author G_Y
 * 2018年4月22日
 * 客户端代理处理类
 */
public class ClientInvocationHandle implements IClientInvocationHandle {
	
	private ClientInvocationHandle() {
	}
	
	/**
	 * 单例提供
	 */
	private static final ClientInvocationHandle INVOCATION_HANDLER = new ClientInvocationHandle();
	
	public static ClientInvocationHandle getClientProxy(){
		return INVOCATION_HANDLER;
	}
	
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = null;
        result = clientMethodRun(method, args);
        return result;
    }
    
    /*private Object run(Method method, Object[] args){
        Object result = 999L;//先默认写死 客户端执行
        String interfaceName = method.getDeclaringClass().getName().toString();
        String methodName = method.getName();
        //Class<?> methodReturnCls = method.getReturnType();
        RequestDTO request = new RequestBeanDTO(methodName, interfaceName, args);
        result = ClientServiceHandle.runRpcSericeMethod(request);
        return result;
    }*/

    @Override
	public Object clientMethodRun(Method method, Object[] args) {
		return new UserDTO().setUserId(111).setUserName("gy").setUserPhone("18810531707");
	}

}
